import { objDeepCopy,getDateString } from "@/assets/js/common.js";
import commonObject from "@/assets/js/xm.js";
let Controller = {
	created() {
		this.init();
	},
	mounted() {
		
	},
	methods: {
		init() {
			// this.getList(this);
		},
		/**
		 * 提交
		 */
		submitBarcode(){
			let dataList = this.Model.TableSelectData
			if(!dataList.length){
				this.$message.error('请至少选择一项')
				return
			}
			let barcodeList = []
			let supplierId = ''
			for(let item of dataList){
				if(!supplierId){
					supplierId=item.supplierId
				}else if(supplierId!=item.supplierId){
					this.$message.error('已选供应商ID不一致，不能提交')
					return
				}
				barcodeList.push(item.barCode+'')
			}
			this.$ajax({
				method: 'post',
				url:`${this.apiTest}/supplier/supplierQualityRecordReturn/addQualityReturn`,
				data:barcodeList
			}).then((res)=>{
				var data = res.data;
				if(data.status == 200&&data.result){
					this.$message.success('提交成功')
				}else{
					this.$message.error(data.msg||'请求失败')
				}
			});
		},
		//获取列表
		getList(barcode) {
			var apiTest = this.apiTest;
			this.$ajax({
					method: 'get',
					url:`${apiTest}/supplier/supplierQualityRecordReturn/getQualityReturnByBarCode?BarCode=${barcode}`,
			    }).then((res)=>{
					var data = res.data;
					if(data.status == 200&&data.result){
						data.result.indexNumber = this.Model.tableData.length+1
						this.Model.tableData.push(data.result)
					}else{
			
					}
				});
		},
		//返回上一页
		returnPage(){
			this.$router.push({path: 'qualityReturnsList'})
		},
		warehousing(row) {
			this.Model.warehousingDialogStatus = row.status;
			this.Model.warehousingDialogFlag = true;
		},
		handleSelectionChange(val) {
			this.Model.TableSelectData=[...val]
		},
		handleCurrentChange(val) {
			var params = this.Model.searchFromData;
			this.getList(this,params,val);
		},
		handleSizeChange(val) {
			var params = this.Model.searchFromData;
			this.getList(this,params,undefined,val);
		},
		cardClick(color) {
			this.Model.cardSelected = color;
		},
		showChild(val) {
			this.Model.searchFromData = val;
		},
		toSearch(val) {
			
			var params = this.Model.searchFromData;
			let barcode
			if(params&&params.BarCode){
				barcode=params.BarCode
			}
			this.getList(barcode);
		},
		toClear(val) {
			this.Model.searchFromData = {};
		},
		toExport(val) {
		  console.log(val);
		},
		tips(that,type,message) {
			that.$message({
				message: message,
				type: type
			});
		},
	},
	watch:{
		$route:{
		　　　handler(newValue, oldValue) {
				
		　　　},
		　　　deep: true
		},
  	
	},
	filters:{
		objFilters:function(value){
			
		}
	}
}
export default Controller;
